package com.toubutu.audio.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.toubutu.audio.admin.entity.UserRole;
import com.toubutu.audio.admin.mapper.UserRoleMapper;
import com.toubutu.audio.admin.service.RoleService;
import com.toubutu.audio.admin.service.UserRoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 戒燥
 * @since 2023-09-30
 */
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {

    @Resource
    private RoleService roleService;
    @Override
    public Map<Long, String> getUserRoleMapByUserIds(List<Long> userId) {
        LambdaQueryWrapper<UserRole> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(UserRole::getUserId,userId);
        Map<Long, List<UserRole>> result =
                list(wrapper).stream().collect(Collectors.groupingBy(UserRole::getUserId));
        List<Integer> roleIds = result.values().stream().map(m -> {
            UserRole userRole = (UserRole) m;
            return userRole.getRoleId();
        }).collect(Collectors.toList());
        Map<Integer, String> roleNameByRoleIds = roleService.getRoleNameByRoleIds(roleIds);
//        result.values().stream().map()

        return null;
    }
}
